home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / bserverdir / sources / server / modeid.c < prev    next >
C/C++ Source or Header  |  1994-11-29  |  3KB  |  128 lines

  1. #include <exec/memory.h>
  2. #include <graphics/displayinfo.h>
  3. #include <graphics/modeid.h>
  4.  
  5. #include "/include/server.h"
  6.  
  7. #include <clib/alib_protos.h>
  8. #include <clib/exec_protos.h>
  9. #include <clib/graphics_protos.h>
  10. #include <string.h>
  11.  
  12. struct List *ModeList;
  13. struct ModeNode *DisplayNode;
  14. ULONG DisplayID = PAL_MONITOR_ID;
  15.  
  16. char DefaultModeName[DISPLAYNAMELEN];
  17.  
  18.  
  19. void DeleteModeList( void )
  20. {
  21. struct ModeNode *ModeNode;
  22.  
  23. while (ModeList->lh_Head->ln_Succ)
  24.     {
  25.     ModeNode=(struct ModeNode *)ModeList->lh_Head;
  26.     RemHead (ModeList);
  27.     FreeVec( ModeNode );
  28.     }
  29. FreeVec( ModeList );
  30. }
  31.  
  32.  
  33. struct List *CreateModeList(void)
  34. {
  35. UWORD Index = 0;
  36. ULONG NewDisplID;
  37. struct DimensionInfo DimInfo;
  38. struct NameInfo NameInfo;
  39. struct ModeNode *NewNode;
  40.  
  41. if ( ModeList = AllocVec( sizeof(struct List), MEMF_PUBLIC ) )
  42.     NewList( ModeList );
  43. else
  44.     return( NULL );
  45.  
  46. NewDisplID=INVALID_ID;
  47.  
  48. while ( ( NewDisplID = NextDisplayInfo( NewDisplID ) ) != INVALID_ID )
  49.     if ( ( NewDisplID & MONITOR_ID_MASK ) && ( !ModeNotAvailable( NewDisplID ) ) )
  50.         if ( GetDisplayInfoData( NULL, (UBYTE *)&DimInfo, sizeof(struct DimensionInfo), DTAG_DIMS, NewDisplID ) )
  51.             if ( GetDisplayInfoData( NULL, (UBYTE *)&NameInfo, sizeof(struct NameInfo), DTAG_NAME, NewDisplID ) )
  52.                 if ( NewNode = AllocVec( sizeof(struct ModeNode), MEMF_CLEAR ) )
  53.                 {
  54.                 NewNode->mn_Node.ln_Name = NewNode->mn_Name;
  55.                 NewNode->mn_DisplayID = NewDisplID;
  56.                 NewNode->mn_Index = Index++;
  57.                 strcpy( NewNode->mn_Name, NameInfo.Name );
  58.                 AddTail( ModeList, (struct Node *)NewNode );
  59.                 }
  60.  
  61. if ( !(ModeList->lh_Head->ln_Succ) )
  62.   {
  63.    FreeMem( ModeList, sizeof(struct List) );
  64.    return( NULL );
  65.   }
  66.  
  67. if ( DisplayID == INVALID_ID )
  68.     {
  69.     if ( NewNode = (struct ModeNode *)FindName( ModeList, DefaultModeName ) )
  70.         DisplayID = NewNode->mn_DisplayID;
  71.     else
  72.         DisplayID = PAL_MONITOR_ID;
  73.     }
  74.  
  75. return( ModeList );
  76. }
  77.  
  78.  
  79. void GetDisplayNodeFromID( void )
  80. {
  81. DisplayNode = (struct ModeNode *)ModeList->lh_Head;
  82.  
  83. while( DisplayNode && DisplayNode->mn_DisplayID != DisplayID )
  84.     DisplayNode = (struct ModeNode *)DisplayNode->mn_Node.ln_Succ;
  85.  
  86. if ( !DisplayID || !DisplayNode )
  87.     {
  88.     DisplayNode = (struct ModeNode *)ModeList->lh_Head;
  89.     DisplayID = DisplayNode->mn_DisplayID;
  90.     }
  91. }
  92.  
  93.  
  94. void GetDisplayNodeFromName( void )
  95. {
  96. if ( (*DefaultModeName != 0) && (DisplayNode = (struct ModeNode *)FindName( ModeList, DefaultModeName )) )
  97.     DisplayID = DisplayNode->mn_DisplayID;
  98. else
  99.     DisplayID = PAL_MONITOR_ID;
  100. }
  101.  
  102.  
  103. void GetDisplayIDFromNode( UWORD Index )
  104. {
  105. DisplayNode = (struct ModeNode *)ModeList->lh_Head;
  106.  
  107. while( DisplayNode && DisplayNode->mn_Index != Index )
  108.     DisplayNode = (struct ModeNode *)DisplayNode->mn_Node.ln_Succ;
  109.  
  110. DisplayID = DisplayNode->mn_DisplayID;
  111. }
  112.  
  113.  
  114. struct DisplayIDInformation *AllocDisplayIDInformation( ULONG whichDisplayID )
  115. {
  116. struct DisplayIDInformation *diinfo;
  117.  
  118. if ( diinfo = AllocVec( sizeof(struct DisplayIDInformation), MEMF_PUBLIC ) )
  119.     {
  120.     if ( GetDisplayInfoData( NULL, (UBYTE *)&diinfo->di_DisplayInfo, sizeof(struct DisplayInfo), DTAG_DISP, whichDisplayID ) )
  121.         if ( GetDisplayInfoData( NULL, (UBYTE *)&diinfo->di_DimensionInfo, sizeof(struct DimensionInfo), DTAG_DIMS, whichDisplayID ) )
  122.                 if ( GetDisplayInfoData( NULL, (UBYTE *)&diinfo->di_MonitorInfo, sizeof(struct MonitorInfo), DTAG_MNTR, whichDisplayID ) )
  123.                     return( diinfo );
  124.     FreeVec( diinfo );
  125.     }
  126. return( NULL );
  127. }
  128.